<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="common/include :: header('服务单项列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="服务单项-form">
					<div class="select-list">
						<ul>
							<li>
								服务单项名字：<input type="text" name="name"/>
							</li>
							<li>
								是否套餐：
								<select name="carPackage" th:with="type=${@dict.getType('si_car_package')}">
									<option value="">所有</option>
									<option th:each="dict:${type}"
											th:text="${dict.label}"
											th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								服务类型：
								<select name="serviceCatalog" th:with="type=${@dict.getType('si_service_catalog')}">
									<option value="">所有</option>
									<option th:each="dict:${type}"
											th:text="${dict.label}"
											th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								审核状态：
								<select name="auditStatus" th:with="type=${@dict.getType('si_audit_status')}">
									<option value="">所有</option>
									<option th:each="dict:${type}"
											th:text="${dict.label}"
											th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								上架状态：
								<select name="saleStatus" th:with="type=${@dict.getType('si_sale_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:serviceitem:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:serviceitem:export">
		            <i class="fa fa-download"></i> 发起审核
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="common/include :: footer" />
	<!--也就是说这个插件有着分页的功能：里面默认有
	pageSize: 10
	pageNum: 1
	orderByColumn: seq
	isAsc: asc
	-->
	<script th:inline="javascript">
		// var editFlag = [[${@permission.hasPermi('system:serviceitem:edit')}]];
		// var removeFlag = [[${@permission.hasPermi('system:serviceitem:remove')}]];
		// var datas = [[${@dict.getType('sys_normal_disable')}]];

		var carpackageDatas=[[${@dict.getType('si_car_package')}]];
		var serviceCatalogDatas=[[${@dict.getType('cmi_service_type')}]];
		var auditStatusDatas=[[${@dict.getType('si_audit_status')}]];
		var saleStatusDatas=[[${@dict.getType('si_sale_status')}]];
		var prefix = ctx + "/business/serviceItem";
		$(function() {
		    var options = {
		        url: prefix + "/query",
		        createUrl: prefix + "/addPage",
		        updateUrl: prefix + "/editPage?id={id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "seq",
		        modalName: "服务单项",
		        columns: [{	//对应table的表头信息
		            checkbox: true
		        },
		        {
		            field: 'id',
		            title: '服务单项id',
					visible: false
		        },
		        {
		            field: 'name',
		            title: '服务单项名字',
		            sortable: true
		        },

		        {
		            field: 'originalPrice',
		            title: '服务单项原价',
		            sortable: true
		        },
		        {
		            field: 'discountPrice',
		            title: '服务单项折扣价',
		            sortable: true
		        },
				{
					field: 'carPackage',
					title: '是否是套餐',
					align: 'center',
					formatter: function(value, row, index) {//当前字段的值和与数据库查询出的value比对，是否显示数据库label
						// console.log(value, datas);
						return $.table.selectDictLabel(carpackageDatas, value);
					}
				},
				{
					field: 'info',
					title: '备注信息',
					sortable: true
				},
				{
					field: 'createTime',
					title: '创建时间',
					sortable: true
				},
				{
					field: 'serviceCatalog',
					title: '服务分类',
					align: 'center',
					formatter: function(value, row, index) {//当前字段的值和与数据库查询出的value比对，是否显示数据库label
						return $.table.selectDictLabel(serviceCatalogDatas, value);
					}
				},
				{
					field: 'auditStatus',
					title: '审核状态',
					align: 'center',
					formatter: function(value, row, index) {//当前字段的值和与数据库查询出的value比对，是否显示数据库label
						return $.table.selectDictLabel(auditStatusDatas, value);
					}
				},
				{
					field: 'saleStatus',
					title: '上架状态',
					align: 'center',
					formatter: function(value, row, index) {//当前字段的值和与数据库查询出的value比对，是否显示数据库label
						return $.table.selectDictLabel(saleStatusDatas, value);
					}
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
						var editFlag='';
						//获取改行数据，判断审核状态，如果是则不能修改
						if(row.auditStatus==1){
							editFlag+='disabled';
						}else if(row.saleStatus==1){//上架也是不能修改的
							editFlag+='disabled';
						}
						var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" ' +
								'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						//获取该行数据，判断上架状态，如果是则添加下架超链接；
						if(row.saleStatus==1){
							actions.push('<a class="btn btn-success btn-xs ' + '' + '" href="javascript:void(0)" ' +
									'onclick="saleOff(\'' + row.id + '\')"><i class="fa fa-edit"></i>下架</a> ');
						}else {
							actions.push('<a class="btn btn-info btn-xs ' + '' + '" href="javascript:void(0)" ' +
									'onclick="saleOn(\'' + row.id + '\')"><i class="fa fa-edit"></i>上架</a> ');
						}
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});
		//上架：依赖框架发送ajax请求
		function saleOn(id) {
			//弹出确认框（模态框）:其中确认后执行函数--》发送ajax请求
			$.modal.confirm("是否确认上架？",function () {
				$.operate.submit(prefix+"/saleOn?id="+id,"post");
			});
		}
		function saleOff(id) {
			$.modal.confirm("是否确认下架？",function () {
				$.operate.submit(prefix+"/saleOff?id="+id,"post");
			});
		}
	</script>
</body>
</html>